<?php


namespace app\index\validate;


use app\index\exception\ParamsException;
use app\index\exception\RequestTypeException;
use app\index\model\UserModel;
use think\Validate;


class ValidateUser extends Validate
{

    protected $model;

    public function __construct()
    {
        $this->model = new UserModel();
    }

    public $rule = [
        "id|ID"=>"require|number|gt:0|data_exists",
//        "name|姓名"=>"require|max:20",
        "phone|手机号"=>"require|mobile|is_phone",
        "password|密码"=>"require|alphaDash|min:6|max:18|is_password"
    ];

    public  $message = [
        "phone.is_phone"=>"手机号未注册",
        "password.is_password"=>"密码错误"
    ];



    public function sceneLogin(){
        return $this->only(["phone","password"]);
    }

    public function is_password($value,$rule,$data){
        $userData = UserModel::where("phone",$data["phone"])->find();
        return (bool)password_verify($value,$userData["password"]);

    }

    public function is_phone($value){
        $res = UserModel::where("phone",$value)->find();
        return (bool)$res;
    }





}